package Thread;
//实验：在main方法中定义两个线程 各自循环10000次 每次循环时对num++
public class Test2 {
    public static int num=0;

    public static void main(String[] args) {
        Thread t1=new Thread(){
          public void run(){
              for (int i=0;i<10000;i++){
                  num++;
              }
          }
        };

        Thread t2=new Thread(){
            public void run(){
                for (int i=0;i<10000;i++){
                   num++;
                }
            }
        };
        t1.start();
        t2.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(num);
    }
}
